<script lang="ts" setup>
import Pagination from 've-pagination/index.vue'
import {initTableHeight} from '@/assets/js/tableHeight'
import {nextTick, ref} from 'vue'
import {createEmitter} from "@/assets/js/eventBus.ts";
import {SchedulingLogVo} from "@/interface/vo/task/schedulingLogVo.ts";
import {ResData} from "@/interface/ResData.ts";
import {getSchedulingLogByPage} from "@/api/result/schedulingLog";
import Search from '@/view/task-execution-logs/search/index.vue'
import Table from '@/view/task-execution-logs/table/index.vue'

const emitter = createEmitter()
const pageRef = ref()
const searchRef = ref()
const tableRef = ref()
nextTick(() => {
  initTableHeight(pageRef, searchRef, tableRef, 0)
})
const onSubmit = (form: any) => {
  getTableData(form)
}
const onReset = (form: any) => {
  getTableData(form)
}

const pageSize = ref(10)

const handleSizeChange = (val: number) => {
  pageSize.value = val
  emitter.emit('refresh', {pageSize: val})
}

const current = ref(1)

const handleCurrentChange = (val: number) => {
  current.value = val
  emitter.emit('refresh', {page: val})
}


const tableLoading = ref(false)

const tableData = ref<Array<SchedulingLogVo>>([])

const total = ref(0)

const getTableData = async (form: {}) => {
  tableLoading.value = true
  const res = <ResData>await getSchedulingLogByPage(form)
  tableLoading.value = false
  if (res.ok) {
    tableData.value = res.data.records
    total.value = res.data.total
  }
}
</script>

<template>
  <div ref="pageRef" class="page">
    <Search ref="searchRef" @onReset="onReset" @onSubmit="onSubmit"/>
    <Table
        ref="tableRef"
        :loading="tableLoading"
        :tableData="tableData">
      <template #pagination>
        <Pagination
            :current="current"
            :pageSize="pageSize"
            :total="total"
            @handleCurrentChange="handleCurrentChange"
            @handleSizeChange="handleSizeChange"/>
      </template>
    </Table>
  </div>
</template>

<style lang="scss" scoped>

</style>
